package com.molichuxing.utils;

import com.molichuxing.framework.utils.EmailUtil;
import com.molichuxing.property.EmailTemplateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.List;

/**
 * 用户token工具类
 *
 * @author zoumingyu
 * @date 2019年8月19日
 *
 */
@Component
public class ScheduleEmailUtil {
	private static final Logger logger = LoggerFactory.getLogger(ScheduleEmailUtil.class);


	@Value("${email_account}")
	private String emailAccount;

	@Value("${email_password}")
	private String emailPassword;

	/**
	 * 发送邮件
	 * @param subject 标题
	 * @param content 内容
	 * @param emailTo 收件人
	 * @return
	 */
	public boolean send(String subject, String content, String emailTo) {
		return EmailUtil.sendMail(emailAccount, emailPassword, subject, content, emailTo);
	}

	public void sendMail(String subject, String content, List<String> emails, String s, InputStream is) {
		 EmailUtil.sendMail(emailAccount, emailPassword, subject, content, emails,s,is);
	}

	/**
	 * 商家还款提前三天
	 * @param orderCode
	 * @param date
	 * @return
	 */
	public String editorPurchaseOrderReminderContent(String orderCode,String date) {
		String content = EmailTemplateEnum.PURCHASE_ORDER_REPAYMENT_DATE_REMINDER.getTemplate();
		content = content.replace("${orderCode}", orderCode);
		content = content.replace("${date}", date);
		return content;
	}

	/**
	 * 商家还款逾期一天
	 * @param orderCode
	 * @param date
	 * @return
	 */
	public String editorPurchaseOrderOverdueReminderContent(String orderCode,String date) {
		String content = EmailTemplateEnum.PURCHASE_ORDER_REPAYMENT_OVERDUE_REMINDER.getTemplate();
		content = content.replace("${orderCode}", orderCode);
		content = content.replace("${date}", date);
		return content;
	}

}
